/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controllers;

/**
 *
 * @author ozgencetinkaya
 */

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import javax.servlet.ServletException;
import java.io.*;
import java.util.*;
import DAO.UserDAO;
import model.UserBean;

@Controller
public class AccountController {
    
    @RequestMapping("account.htm")
    public void account(HttpServletRequest request,HttpServletResponse response) throws IOException{
        Enumeration enames;
        HttpSession session = request.getSession(true);
        enames = session.getAttributeNames();

        if (!enames.hasMoreElements()) {
            response.sendRedirect("signin.htm");
        }
        else{
            UserBean currentUser = (UserBean)(session.getAttribute("currentSessionUser"));
            if(currentUser.isValid())  {
                if(currentUser.getRoleId() == 1){
                    response.sendRedirect("accountwillingwalker.htm");
                }
                else{
                    response.sendRedirect("accountisolatedperson.htm");
                }
            }
            else
                response.sendRedirect("signin.htm");
        }
    }
    
}
